﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System .Data ;
using System .Data .SqlClient ;
using dhDataAcess.orderLinqDAL ;
using dhDataAcess.dataAcess;

namespace dhDataAcess.orderDAL
{
  public   class stockPositionDAL
    {
      string tableName = "stockPosition";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public stockPositionDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction ;
            conn = _conn;
        }
        /// <summary>
        /// 插入仓位信息表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int stockPositionInsert(stockPositionModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string insertstr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                    new SqlParameter ("@mark",row .mark ),
                                    new SqlParameter ("@updateUser",row .updateUser),
                                    new SqlParameter ("@updateDate",row .updateDate),
                                    new SqlParameter ("@createUser",row .createUser),
                                    new SqlParameter ("@createDate",row .createDate),
                                    new SqlParameter ("@posMark",row .posMark ),
                                    new SqlParameter ("@stockName",row .stockName ),
                                    new SqlParameter ("@posName",row .posName)
                                  };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 插入仓位信息表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int stockPositionTableInsert(orderDataSet.stockPositionDataTable stockPositionTable)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter par = new SqlParameter("@stockPosition", stockPositionTable);
            par.SqlDbType = SqlDbType.Structured;
            par.TypeName = "stockpsition";


            cmd.Parameters.Add(par);
            cmd.CommandText = "stockpostion";

            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 更新仓位信息表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int stockPositionUpdate(stockPositionModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updatestr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                    new SqlParameter ("@mark",row .mark ),
                                    new SqlParameter ("@updateUser",row .updateUser),
                                    new SqlParameter ("@updateDate",row .updateDate),
                                    new SqlParameter ("@createUser",row .createUser),
                                    new SqlParameter ("@createDate",row .createDate),
                                    new SqlParameter ("@posMark",row .posMark ),
                                    new SqlParameter ("@stockName",row .stockName ),
                                    new SqlParameter ("@posName",row .posName)
                                  };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updatestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行仓位信息表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int stockPositionDel(string posName)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deletestr = baseBLL.dTableColumnRead.delSqlStr (tableName).ToString();
            SqlParameter[] para = {
                                    
                                    new SqlParameter ("@posName",posName)
                                  };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = deletestr ;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
